package StudyCode.summary.myfile;

import java.io.File;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class PahtIsFileANDExitsAndWritable {
	public static void main(String[] argv) {
		String filename = "E:\\迅雷下载\\test1.txt";
		System.out.println("文件 " + filename + "是否存在并且可写入？ " + checkFile(filename));
	}

	private static boolean checkFile(String filename) {
		File f = new File(filename);

		if (!f.exists()) {
			return false;
		}

		if (f.exists() && !f.isFile()) {
			return false;
		}

		try {
			return f.canWrite();
		} catch (Exception e) {
			return false;
		}
	}
}
